package cn.skyquant.quant4j.api.strategy;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;
import java.util.List;

public class StrategyParameter implements Serializable {
    private static final long serialVersionUID = 1L;
    public final String name;
    public final String desc;
    public final String value;

    public StrategyParameter(String name, String desc, String value) {
        this.name = name;
        this.desc = desc;
        this.value = value;
    }

    @Override
    public String toString() {
        return name+"_"+desc+"_"+value;
    }

    public static final String toJSONString(List<StrategyParameter> parameterList){
        return JSONObject.toJSONString(parameterList);
    }


    public static void format(List<StrategyParameter> list,String paramstr){
        JSONArray jsonArray = JSONObject.parseArray(paramstr);
        for(int i=0;jsonArray!=null && i<jsonArray.size();i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String name = jsonObject.getString("name");
            String desc = jsonObject.getString("desc");
            String value = jsonObject.getString("value");
            list.add(new StrategyParameter(name,desc,value));
        }
    }
}
